// CSE 142 Winter 2008, Marty Stepp // // This program counts factors of various integers. // (We'll work on it more in future lectures.) // public class Factors { public static void main(String[] args) { System.out.println(countFactors(60)); System.out.println(countFactors(3)); System.out.println(countFactors(24)); } // Returns the number of factors of the given integer. // Assumes that a non-negative number is passed. public static int countFactors(int number) { int count = 0; // cumulative count of factors for (int i = 1; i <= number; i++) { if (number % i == 0) { // i is a factor of number count++; // count = count + 1; } } return count; } }